<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>聚合二维码管理</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script src="js/json2.js" type="text/javascript"></script>
	<script type="text/javascript">

	$(document).ready(function() {
		queryUnionQRCodeList(1);
	});
	
	//查询列表
	function queryUnionQRCodeList(){
		//查询最近修改的一页列表
		queryUnionQRCodeListByPageNumber(1);
	}
	
	function deleteUnionCode(obj){
		$.dialog({
			type: "warn",
			content: "您确定要删除该二维码吗？",
			onOk: function() {
				$.openLoading();
				var editTr = $(obj).parent('td').parent('tr')[0];
				var codeId = editTr.childNodes[1].innerHTML;
				$.ajax({
					url : "<%=path%>/unionScanConfig/deleteUnionCode",
					type: "POST",
					async:false,
					data:{
						codeId:codeId
					},
					dataType: "json",
					success: function(data) {
						$.closeLoading();
						$.message(data.result,data.message);
						setTimeout(function(){
							window.location.reload();
						},"2000")
						// queryUnionQRCodeList(1);
					}
				});
			}
		});
		
		
	}
	
	function queryUnionQRCodeListByPageNumber(pageIndex){
		var size = 8;
		var partnerCode = $.trim($('#partnerCode').val());
		var unionScanQRCodeName = $.trim($('#unionScanQRCodeName').val());
		/* 
			参数：
			current：当前页码
			size：分页每页条数
			--partnerCode：合作伙伴代码
			unionScanQRCodeName:二维码名称
		*/
		var param = {current:pageIndex,size:size,unionScanQRCodeName:unionScanQRCodeName};
		$.openLoading();
		$.ajax({
			url : "<%=path%>/unionScanConfig/queryUnionQRCodeListByPageNumber",
			type : 'POST',
			async : false,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page)){
					return;
				}
				var flag=page.obj 
				var firstbutton ='';
				if(flag){
					 firstbutton ="<input class='input_fxk' name='radioUnionQCCode' type='radio' value='#'>@<input class='input_fxk' name='checkRule' type='checkBox' value='#'>";
				}else{
					 firstbutton ="<input class='input_fxk' name='radioUnionQCCode' type='radio' value='#'>"
				}
				var lastbutton = "<a href='javascript:void(0)' onClick='editUnionCode(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='deleteUnionCode(this);return false'>删除</a>";
				var tableContent = creatTable1("id@TDH,unionCodeName,unionCodeDesc",page,firstbutton,lastbutton);
				var tableObj = $("#unionQRCodeTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"102");
				var pageDIV = $("#unionQRCodePageDIV");
				bindradio();
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
			}
		});
	}
	//重置
	function reset(){
		$("#unionScanQRCodeName").val("");
	}
	//展示选择合作伙伴 窗体
	function openPartnerDiv(){
		queryChannelInfo(1);
	}
	
	//关闭 选择合作伙伴 弹出层
	function closeChannelInfoDiv(){
		$("#channelInfoDiv").CloseDiv();	
		$('#channelCode_choose').val("");
		$('#channelName_choose').val("");
	}
	
	//点击“确定”按钮，选择合作伙伴
	function chooseChannelInfo(){
		var selected = $("input[name='radioChannelInfo']:checked");
		if(selected.length==0){
			$.message("error", "请选择一个合作伙伴");
			return;
		}
		var channelCode = selected.parent().parent().children(" td:eq(1)").html();
		$('#partnerCode').val(channelCode);
		closeChannelInfoDiv();
	}
	
	//拼接查询合作伙伴 字符串
	function queryChannelInfo(pageIndex){
		var channelCode = $.trim($('#channelCode_choose').val());
		var channelName = $.trim($('#channelName_choose').val());	
		loadChannelInfo({current:pageIndex,size:8,channelCode:channelCode,channelName:channelName});
	}
	
	//查询合作伙伴 请求的是nlifePlanController 代码复用
	function loadChannelInfo(param){
		$.openLoading();
		$.ajax({
			url : "<%=path%>/nlifePlanConfig/queryChannelInfoPageByCriteria?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page)){
					return;
				}
				var radioObj ="<input class='input_fxk' name='radioChannelInfo' type='radio' value=''>";
				var fieldNames = "channelCode,channelName";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#channelInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);			
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"42");
				var pageDIV = $("#channelInfoPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				$('#channelInfoDiv').OpenDiv();
				bindradio();
			}
		});
	}  
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioNlifePlan']").click(function(){
			$("input[name='radioNlifePlan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='radioChannelInfo']").click(function(){
			$("input[name='radioChannelInfo']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}
	
	//点击编辑按钮，跳转编辑界面
	function editUnionCode(obj){
		//当前行的第一个td中保存有id
		var editTr = $(obj).parent('td').parent('tr')[0];
		var codeId = editTr.childNodes[1].innerHTML;
		/* var codeName = editTr.childNodes[2].innerHTML;
		var codeDesc = editTr.childNodes[3].innerHTML; */
		window.location.href="<%=path%>/unionScanConfig/edit?codeId="+codeId;
	}
	//点击新增按钮 ，跳转新增页面
	function addNewUnionCode(){
		window.location.href="<%=path%>/unionScanConfig/add";
	}
	
	//下载二维码
	function downloadQRCode(){
		var selected = $("input[name='radioUnionQCCode']:checked");
		if(selected.length==0){
			$.message("error", "请选择一个二维码");
			return;
		}
		var codeId = selected.parent('td').parent('tr')[0].childNodes[1].innerHTML;
		window.location.href='<%=path%>/unionScanConfig/downloadQRCode?ruleAgentId='+codeId;
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">界面出单管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>聚合二维码管理
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
						 	<td  style="width:'20%' height:'30';text-align: center;">
								<!-- 合作伙伴：	<input id="partnerCode" style="background-color: #ccc;" class="input_text">
	                  	        <input type="button"  class="input_button_2" id="searchDeptBtn"  value="请选择" onClick="openPartnerDiv()"/>&nbsp;&nbsp; -->
	                  	                二维码名称：<input id="unionScanQRCodeName" type="text" class="input_text">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryUnionQRCodeListByPageNumber(1)" />&nbsp;
								<input type="button" class="input_button_1" id="" value="重置" onClick="reset()" />&nbsp;
							</td>
						</tr>
						<tr height="30px">
							<input type="button" class="input_button_1" id="" value="下载" onClick="downloadQRCode()" />&nbsp;&nbsp;
							<input type="button" class="input_button_1" id="" value="新增" onClick="addNewUnionCode()" />
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
				</td>
			</tr>
			<tr>
				<td>
					<table id="unionQRCodeTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th></th>
								<th>二维码名称</th>
								<!-- <th style="width: 20%">合作伙伴</th> -->
								<th style="width: 10%">详情</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="unionQRCodePageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
	<!-- begin ------------------------合作伙伴 DIV 默认隐藏--------------------------->
	<!-- 选择 合作伙伴 div-->
  	<div id="channelInfoDiv" style="display:none;width:90%;text-align: center;">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeChannelInfoDiv()"/></td>
					</tr>
				</table>
		</div>
		<table class="table_02" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
								合作伙伴代码：<input name="txt3"  id="channelCode_choose" class="input_text" />&nbsp;&nbsp;
								合作伙伴名称：<input name="txt3" id="channelName_choose" class="input_text" />&nbsp;&nbsp;
								<input type="button"  class="input_button_1" value="查询" onClick="queryChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="确定" onclick="chooseChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeChannelInfoDiv()" class="input_button_3"/>
		</div>
	</div>
<!-- end ------------------------出单机构 DIV 默认隐藏--------------------------->	
</body>
</html>